const DB = wx.cloud.database()
let 角色=""
let 手机号=""
let 车位数=""
let 留言=""
let 车牌号=""
let collection=""
Page({
  data:{
    user_type:"乘客", //["司机","乘客"]
    db_list:{
      乘客:"user_passenger",
      司机:"user_driver"
    },
    startLocation:null,
    endLocation:null,
  },
  onLoad: function (options) {
    var that = this
    that.setData({user_type: options.user_type })
  },
  add出发地(event){
    wx.navigateTo({
      //url: '/pages/position/position?longitude='+res["longitude"]+"&"+"latitude="+res["latitude"],
      url:"/pages/position/position?isStartPos=true",
      success: (result) => {
        
      },
      fail: (res) => {
        console.log(res)
      },
      complete: () => {}
    });
  },
  add目的地(event){
    wx.navigateTo({
      //url: '/pages/position/position?longitude='+res["longitude"]+"&"+"latitude="+res["latitude"],
      url:"/pages/position/position?isStartPos=false",
      success: (result) => {
        
      },
      fail: (res) => {
        console.log(res)
      },
      complete: () => {}
    });
  },
  add角色(event){
    角色 = event.detail.value
  },
  add手机号(event){
    手机号 = event.detail.value
  },
  add留言(event){
    留言 = event.detail.value
  },
  add车位数(event){
    车位数 = event.detail.value
  },
  add车牌号(event){
    车牌号 = event.detail.value
  },
  addData(){
    collection=this.data.db_list[this.data.user_type]
    console.log(DB.collection(collection))
    DB.collection(collection).add({
      data:{
        出发地:this.data.startLocation.title,
        目的地:this.data.endLocation.title,
        startLocation:this.data.startLocation,
        endLocation:this.data.endLocation,
        角色:角色,
        手机号:手机号,
        留言:留言,
        车位数:车位数,
        
      },
      success(res){
        console.log("添加成功", res)
        wx.switchTab({
          url: '../found_passenger/found_passenger',
        })
      },
      fail(res){
        console.log("添加失败", res)
      }

    })
  },

})